package com.pignest.hotel.definition;

import com.pignest.hotel.beans.Room;

/** 
 * 房间维修状态
 * */
public enum RoomRepairStatus {
	
	NORMAL("正常", "white.png")
	, REPAIR("维修", "repair.png")
	;
	
	private String cname;
	private String icon;
	public final static RoomRepairStatus DEFAULT = NORMAL;

	RoomRepairStatus(String cname, String icon){
		this.cname = cname;
		this.icon = icon;
	}
	
	public String getName() {
		return cname;
	}
	
	public String getImage() {
		return icon;
	}
	
	public boolean is(Room room) {
		return room != null && name().equals(room.getRepairStatus());
	}
	
	/////////////////////////////////////////////////////////////////////////////////////
	
	public static RoomRepairStatus getByCName(String cname) {
		RoomRepairStatus[] values = RoomRepairStatus.values();
		for (int i = 0; i < values.length; i++) {
			if (values[i].cname.equals(cname))
				return values[i];
		}
		return DEFAULT;
	}
	
	/** no exception version of {@link #valueOf(String)} */
	public static RoomRepairStatus valueof(String name) {
		try {
			return RoomRepairStatus.valueOf(name);
		} catch (RuntimeException e) {//IllegalArgumentException, NullPointerException
		}
		return null;
	}
	
	public static String[] names() {
		RoomRepairStatus[] values = RoomRepairStatus.values();
		String[] r = new String[values.length];
		for (int i = 0; i < values.length; i++) {
			r[i] = values[i].name();
		}
		return r;
	}
	
	public static String[] cnames() {
		RoomRepairStatus[] values = RoomRepairStatus.values();
		String[] r = new String[values.length];
		for (int i = 0; i < values.length; i++) {
			r[i] = values[i].cname;
		}
		return r;
	}
}
